package com.quientienemail.com.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DockPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.KeyboardListener;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;

public class PrincipalMod implements EntryPoint {
    private TextBox textBox;
    private Button button;
    private Label label;
    private HTML html;
    

    private DeterminaEmpresa detemp;
    
	public void onModuleLoad() {
		// TODO Auto-generated method stub 
	       DockPanel dockPanel = new DockPanel();
	        detemp = new DeterminaEmpresa();
	        
	        textBox = new TextBox();
	        button = new Button("Click Me");
	        label = new Label("NA");
	        html = new HTML();
	        
	        
	        
	        dockPanel.add(textBox, DockPanel.NORTH);
	        //dockPanel.add(button, DockPanel.CENTER);
	        dockPanel.add(html, DockPanel.SOUTH);
	        
	        textBox.addKeyboardListener(new KeyboardListener()
	        {

				public void onKeyDown(Widget arg0, char arg1, int arg2) {
					// TODO Auto-generated method stub
					
				}

				public void onKeyPress(Widget arg0, char arg1, int arg2) {
					// TODO Auto-generated method stub
			      
					
					
				}

				public void onKeyUp(Widget arg0, char arg1, int arg2) {
					// TODO Auto-generated method stub
					int i = 0;
					String cad, cad1, cad2;
					cad = textBox.getText();
					int ok = 1;
					label.setText(textBox.getText());	
					
					while ( ok == 1 ){
						i++;
						if (i <= cad.length())
						{
							cad1 = cad.substring(0, i) ;
							cad2 = detemp.Determina(cad1);
							if (cad2.length()!= 0)
							{
								html.setHTML(detemp.DeterminaLink(cad2));
								
								label.setText(cad2);
								ok = 0;
							}
							
						}else
						{
						  ok = 0;	
						}
					}
					
					
						
						
					
					
				}
	        });
	        

	       
	        RootPanel.get("gwtContainer").add(dockPanel);
	        
	        
	        }
	}

